import java.util.Stack;

/**
 * @author LKQ
 * @date 2021/12/12 15:47
 * @description 栈中存放每一次入栈比较的最小值。
 */
public class Solution1 {
    public static void main(String[] args) {
        MinStack1 obj = new MinStack1();
        obj.push(2147483646);
        obj.push(2147483646);
        obj.push(2147483647);
        int top = obj.top();
        obj.pop();
        int min = obj.getMin();
        obj.pop();
        min = obj.getMin();
        obj.pop();
    }
}

class MinStack1 {

    /**
     * 数组栈, [当前值, 当前最小值]
     */

    private Stack<int[]> stack = new Stack<>();

    public MinStack1() {

    }

    public void push(int x) {
        if (stack.isEmpty()){
            stack.push(new int[]{x, x});
        }else {
            stack.push(new int[]{x, Math.min(x, stack.peek()[1])});
        }
    }

    public void pop() {
        stack.pop();
    }

    public int top() {
        return stack.peek()[0];
    }

    public int getMin() {
        return stack.peek()[1];
    }
}
